let frame = 0
let allFrameCount = 0
let lastTime = Date.now()
let lastFameTime = Date.now()

const loop = function () {
  let now = Date.now()
  let fs = now - lastFameTime
  let fps = Math.round(1000 / fs)

  lastFameTime = now
  // 不置 0，在动画的开头及结尾记录此值的差值算出 FPS
  allFrameCount++
  frame++

  if (now > 1000 + lastTime) {
    const fps = Math.round((frame * 1000) / (now - lastTime))
    frame = 0
    lastTime = now
    return fps
  }
}

export default loop
